package com.ruoyi.project.rostering.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.rostering.domain.Rostering;
import com.ruoyi.project.rostering.service.IRosteringService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 排班管理Controller
 * 
 * @author zhf
 * @date 2022-11-05
 */
@RestController
@RequestMapping("/rostering/rostering")
public class RosteringController extends BaseController
{
    @Autowired
    private IRosteringService rosteringService;

    /**
     * 查询排班管理列表
     */
    @PreAuthorize("@ss.hasPermi('rostering:rostering:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rostering rostering)
    {
        startPage();
        List<Rostering> list = rosteringService.selectRosteringList(rostering);
        return getDataTable(list);
    }

    /**
     * 导出排班管理列表
     */
    @PreAuthorize("@ss.hasPermi('rostering:rostering:export')")
    @Log(title = "排班管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rostering rostering)
    {
        List<Rostering> list = rosteringService.selectRosteringList(rostering);
        ExcelUtil<Rostering> util = new ExcelUtil<Rostering>(Rostering.class);
        util.exportExcel(response, list, "排班管理数据");
    }

    /**
     * 获取排班管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('rostering:rostering:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rosteringService.selectRosteringById(id));
    }

    /**
     * 新增排班管理
     */
    @PreAuthorize("@ss.hasPermi('rostering:rostering:add')")
    @Log(title = "排班管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rostering rostering)
    {
        return toAjax(rosteringService.insertRostering(rostering));
    }

    /**
     * 修改排班管理
     */
    @PreAuthorize("@ss.hasPermi('rostering:rostering:edit')")
    @Log(title = "排班管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rostering rostering)
    {
        return toAjax(rosteringService.updateRostering(rostering));
    }

    /**
     * 删除排班管理
     */
    @PreAuthorize("@ss.hasPermi('rostering:rostering:remove')")
    @Log(title = "排班管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rosteringService.deleteRosteringByIds(ids));
    }
}
